#!/bin/bash
#auth:dd
#content: modify replication db

{% if mysql_repl_role == "master" %}
{% for i in mysql_db %}
{% if i.replicate|default(1) %}
sed -i "/server-id/a replicate-do-db={{i.name}}" /etc/my.cnf
sed -i "/server-id/a binlog-do-db={{i.name}}" /etc/my.cnf
{% endif %}
{% endfor %}

{% for i in mysql_db %}
{% if not i.replicate|default(1) %}
sed -i "/server-id/a binlog-ignore-db={{i.name}}" /etc/my.cnf
{% endif %}
{% endfor %}
{% endif %}


{% if mysql_repl_role == "slave" %}
{% for i in mysql_db %}
{% if i.replicate|default(1) %}
sed -i "/server-id/a replicate-do-db={{i.name}}" /etc/my.cnf
{% endif %}
{% endfor %}

{% for i in mysql_db %}
{% if not i.replicate|default(1) %}
sed -i "/server-id/a binlog-ignore-db={{i.name}}" /etc/my.cnf
{% endif %}
{% endfor %}
{% endif %}